/**
 * 
 */
package hottargui.config;

import hottargui.framework.BoardStrategy;
import hottargui.framework.GameData;
import hottargui.framework.PlayerColor;
import hottargui.framework.Tile;
import hottargui.framework.TileType;
import hottargui.standard.StandardTile;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class DeltaBoardStrategy implements BoardStrategy {

	public void setupBoard(GameData gameData) {
		List<Tile> boardConf = gameData.getBoardConfiguration();
		List<TileType> deck = new ArrayList<TileType>();

		boardConf.clear();

		/* Add saltmine to board in middle slot */
		boardConf.add(new StandardTile(TileType.Saltmine, PlayerColor.None, 3, 3));

		/* Add tiles to deck, total 48 tiles */
		for (int tiles = 1; tiles < 7; tiles++) {
			deck.add(TileType.Oasis);
		}

		for (int tiles = 1; tiles < 13; tiles++) {
			deck.add(TileType.Erg);
		}

		for (int tiles = 1; tiles < 13; tiles++) {
			deck.add(TileType.Reg);
		}

		for (int tiles = 1; tiles < 9; tiles++) {
			deck.add(TileType.Feshfesh);
		}

		for (int tiles = 1; tiles < 7; tiles++) {
			deck.add(TileType.Mountain);
		}

		for (int tiles = 1; tiles < 5; tiles++) {
			deck.add(TileType.Saltlake);
		}

		/* Shuffle deck */
		Collections.shuffle(deck);

		/* Add shuffled deck to board */
		int row = 0;
		int col = 0;
		for (TileType tile : deck) {
			if (row != 3 || col != 3) /* Reserved for saltmine */
			{
				boardConf.add(new StandardTile(tile, PlayerColor.None, row, col));
			}
			col += 1;
			if (col == 7) {
				row += 1;
				col = 0;
			}
		}

		/* Swap all corner tiles with settlements */

		/* remove corner tile placed in position 0,0 */
		boardConf.remove(gameData.getTile(0, 0));
		/* add red settlement tile an place it in postion 0,0 */
		Tile redSettlement = new StandardTile(TileType.Settlement, PlayerColor.Red, 0, 0);
		redSettlement.setOwnerColor(PlayerColor.Red);
		boardConf.add(redSettlement);

		/* remove corner tile placed in position 0,6 */
		boardConf.remove(gameData.getTile(0, 6));
		/* add green settlement tile an place it in postion 0,6 */
		Tile greenSettlement = new StandardTile(TileType.Settlement, PlayerColor.Green, 0, 6);
		greenSettlement.setOwnerColor(PlayerColor.Green);
		boardConf.add(greenSettlement);

		/* remove corner tile placed in position 6,0 */
		boardConf.remove(gameData.getTile(6, 0));
		/* add blue settlement tile an place it in postion 6,0 */
		Tile blueSettlement = new StandardTile(TileType.Settlement, PlayerColor.Blue, 6, 0);
		blueSettlement.setOwnerColor(PlayerColor.Blue);
		boardConf.add(blueSettlement);

		/* remove corner tile placed in position 6,6 */
		boardConf.remove(gameData.getTile(6, 6));
		/* add yellow settlement tile an place it in postion 6,6 */
		Tile yellowSettlement = new StandardTile(TileType.Settlement, PlayerColor.Yellow, 6, 6);
		yellowSettlement.setOwnerColor(PlayerColor.Yellow);
		boardConf.add(yellowSettlement);

		/* Set unit count to 10 on each settlement */
		redSettlement.setUnitCount(10);
		greenSettlement.setUnitCount(10);
		blueSettlement.setUnitCount(10);
		yellowSettlement.setUnitCount(10);
	}
}
